#pragma once

#include "Stdafx.h"

#include "_FXErrorInternal.h"

//<summary>
//Bit patterns for 32 and 64 bit quiet NaNs
//</summary>
#define FXERROR_FLOAT_QNAN ((FXUInt32)0x7FC00000)
#define FXERROR_DOUBLE_QNAN ((FXUInt64)0x7FF8000000000000UL)

//<summary>
//The mask determines if a NaN is quiet or signaling
//</summary>
#define TCERROR_FLOAT_QNAN_MASK   ((FXUInt32) 1 << 22)
#define TCERROR_DOUBLE_QNAN_MASK  ((FXUInt64) 1 << 51)

#define FXERROR_VERIFY_IS_NULL(def_ptr) (def_ptr == NULL)

namespace FXError
{

	namespace FXErrorInternal
	{
		inline FXFloat QuietNaNf()
		{
			FXUInt32 qnan = FXERROR_FLOAT_QNAN;
			return (*(FXFloat*)(&qnan));
		}

		inline FXDouble QuietNaNd()
		{
			FXUInt64 qnan = FXERROR_DOUBLE_QNAN;
			return (*(FXDouble*)(&qnan));
		}			
	};
	
	template<typename T>
	 inline T QuietNaN()
	{
		static_assert(false, "Wrong type template calling Quiet NaN");
		return 0;
	}

	template<>
	inline FXFloat QuietNaN()
	{
		return FXErrorInternal::QuietNaNf();
	}

	template<> 
	inline FXDouble QuietNaN()
	{
		return FXErrorInternal::QuietNaNd();
	}
}
